package com.ruoyi.web.controller.common;

import com.ruoyi.common.annotation.AnonymousPostMapping;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.web.service.SysLoginService;
import com.ruoyi.system.domain.dto.CaptchaDTO;
import com.ruoyi.system.domain.dto.CaptchaLoginDTO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 发送短信验证
 *
 * @author Administrator
 * @date 2022/05/06
 */
@RestController
@RequestMapping("/api/account/verifyCode")
public class AccountController extends BaseController {

    @Autowired
    private SysLoginService loginService;

    /**
     * 发送短信验证码
     *
     * @param captcha 验证码
     * @param request 请求
     * @return {@link AjaxResult}
     */
    @ApiOperation(value = "获取验证码", notes = "填入手机号获取6位数手机验证码。")
    @AnonymousPostMapping(value = "/sendCaptcha")
    public AjaxResult sendCaptcha(@RequestBody CaptchaDTO captcha, HttpServletRequest request) {
        return loginService.sendCaptcha(captcha, request);
    }

    /**
     * 手机验证码登录
     *
     * @param captchaLoginDTO 验证码登录dto
     * @return {@link AjaxResult}
     */
    @AnonymousPostMapping("/captchaLogin")
    public AjaxResult captchaLogin(@Valid @RequestBody CaptchaLoginDTO captchaLoginDTO) {
        return loginService.captchaLogin(captchaLoginDTO);
    }

    /**
     * 重置密码
     *
     * @param captchaLoginDTO
     * @return {@link AjaxResult}
     */
    @AnonymousPostMapping("/resetPassword")
    public AjaxResult resetPassword(@Valid @RequestBody CaptchaLoginDTO captchaLoginDTO){
        return loginService.resetPassword(captchaLoginDTO);
    }

    /**
     * 校验验证码是否正确
     *
     * @param captchaLoginDTO 验证码登录dto
     * @return {@link AjaxResult}
     */
    @AnonymousPostMapping("/checkCerificationCode")
    public AjaxResult checkCerificationCode(@Valid @RequestBody CaptchaLoginDTO captchaLoginDTO){
        return loginService.checkCerificationCode(captchaLoginDTO);
    }

}
